#ifndef __TERRAIN_H__
#define __TERRAIN_H__

class TChunk
{
	int cntlods,sz;
	unsigned int *IBuff;
	TChunk(unsigned int *ind,int ibsiz,int cntl);
	~TChunk();
};

class Terrain
{
	friend class Entity;
	unsigned int width,height;
	float* hmap;
	unsigned char state;
	bool locked;
	unsigned int vertexB;
	unsigned int indicesB;
	unsigned int ct_,cv_;
	Entity* bindedent;

	int cntchunks,chunksx,chunksz;
	void DrawChunk(int i, int j);

	TChunk* chunks;

	void init();
public:
	Terrain();
	Terrain(unsigned int width,unsigned int height);
	Terrain(Terrain& src);
	Terrain(char* filename);
	~Terrain();
	void Draw();
	float GetHeight(unsigned int x,unsigned int z);
	void Lock();
	bool Locked();
	void MakeVBO();
	void Randomize(float minval,float maxval);
	void Randomize(float maxval);
	void Scale(float dy);
	void Set(float y);
	void SetY(unsigned int x,unsigned int z,float y);
	void Smooth(unsigned char blurvalue);
	void Shuffle(float dy);
	void UnLock();
	float GetY(float x,float z);
	float GetY(Entity *ent);

};
#endif